using System;
using miPics.Common;


public partial class UserControl_GalleryList : miPics.BaseUserControl.BaseUserControl
{
	protected void Page_Load(object sender, EventArgs e)
	{
		// hide/show create gallery link
		_CreateGalleryLink.Visible = this._LoginMode;

		// get gallery data into datatable
		miPicsDataAccessTableAdapters.GalleryListTableAdapter GalleryListTableAdapter = new miPicsDataAccessTableAdapters.GalleryListTableAdapter();
		miPicsDataAccess.GalleryListDataTable Galleries = GalleryListTableAdapter.GetData(this._LoginMode);

		// cycle galleries and create user controls
		foreach (miPicsDataAccess.GalleryListRow GalleryRow in Galleries)
		{
			UserControl_GalleryListItem ListItem = (UserControl_GalleryListItem)LoadControl("~/UserControl/GalleryListItem.ascx");

			// set user control values
			ListItem.GalleryID = GalleryRow.GalleryID;
			ListItem.Name = GalleryRow.Name;
			ListItem.Description = GalleryRow.Description;
			ListItem.ImageCount = GalleryRow.ImageCount;

			if (string.IsNullOrEmpty(GalleryRow.Thumbnail))
			{
				ListItem.GalleryImageSrc = null;
			}
			else
			{
				ListItem.GalleryImageSrc = GalleryRow.Thumbnail;
				ListItem.GalleryImageName = ToolKit.GetAltImageName(GalleryRow.ThumbnailName);
				ListItem.GalleryImageWidth = GalleryRow.ThumbnailWidth;
				ListItem.GalleryImageHeight = GalleryRow.ThumbnailHeight;
			}

			// set edit mode
			ListItem.EditMode = this._LoginMode;

			// add list item to placeholder
			_GalleryPlaceHolder.Controls.Add(ListItem);
		}
	}
}